package com.zhaoqi.hr.entity;

import javax.persistence.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 用工需求发布实体
 */
@Entity
@Table(name = "job_postings")
@EntityListeners(AuditingEntityListener.class)
public class JobPosting {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "employer_id", nullable = false)
    private EmployerProfile employer;
    
    @Column(name = "job_title", nullable = false, length = 100)
    private String title; // 岗位标题
    
    @Column(name = "job_description", columnDefinition = "TEXT")
    private String description; // 工作内容描述
    
    @Enumerated(EnumType.STRING)
    @Column(name = "job_type", nullable = false)
    private JobType jobType; // 岗位类型
    
    @Column(name = "work_location", length = 500)
    private String location; // 工作地点
    
    @Column(precision = 10, scale = 2)
    private BigDecimal salary; // 薪资
    
    @Enumerated(EnumType.STRING)
    @Column(name = "salary_type", nullable = false)
    private SalaryType salaryType; // 薪资类型
    
    @Column(name = "required_workers")
    private Integer requiredCount = 1; // 需要人数
    
    @Column(name = "start_time")
    private LocalDateTime startTime; // 工作开始时间
    
    @Column(name = "end_time")
    private LocalDateTime endTime; // 工作结束时间
    
    @Column(name = "skill_requirements", length = 500)
    private String skillRequirements; // 技能要求
    
    @Column(name = "other_requirements", length = 500)
    private String otherRequirements; // 其他要求
    
    @Column(name = "contact_info", length = 200)
    private String contactInfo; // 联系方式
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private JobStatus status = JobStatus.ACTIVE;
    
    @Column(columnDefinition = "TEXT")
    private String auditRemark; // 审核备注
    
    @Column
    private Long auditBy; // 审核人ID
    
    @Column
    private LocalDateTime auditAt; // 审核时间
    
    @Column
    private LocalDateTime publishAt; // 发布时间
    
    @Column
    private LocalDateTime expireAt; // 过期时间
    
    @Column(name = "assigned_worker_id")
    private Long assignedWorkerId; // 分配的劳动者ID
    
    @Column(name = "assigned_at")
    private LocalDateTime assignedAt; // 分配时间
    
    @CreatedDate
    @Column(nullable = false, updatable = false)
    private LocalDateTime createdAt;
    
    @LastModifiedDate
    @Column(nullable = false)
    private LocalDateTime updatedAt;
    
    // 关联关系
    @OneToMany(mappedBy = "jobPosting", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<JobApplication> applications;

    // Getter and Setter methods
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public EmployerProfile getEmployer() {
        return employer;
    }

    public void setEmployer(EmployerProfile employer) {
        this.employer = employer;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public JobType getJobType() {
        return jobType;
    }

    public void setJobType(JobType jobType) {
        this.jobType = jobType;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public BigDecimal getSalary() {
        return salary;
    }

    public void setSalary(BigDecimal salary) {
        this.salary = salary;
    }

    public SalaryType getSalaryType() {
        return salaryType;
    }

    public void setSalaryType(SalaryType salaryType) {
        this.salaryType = salaryType;
    }

    public Integer getRequiredCount() {
        return requiredCount;
    }

    public void setRequiredCount(Integer requiredCount) {
        this.requiredCount = requiredCount;
    }

    public LocalDateTime getStartTime() {
        return startTime;
    }

    public void setStartTime(LocalDateTime startTime) {
        this.startTime = startTime;
    }

    public LocalDateTime getEndTime() {
        return endTime;
    }

    public void setEndTime(LocalDateTime endTime) {
        this.endTime = endTime;
    }

    public String getSkillRequirements() {
        return skillRequirements;
    }

    public void setSkillRequirements(String skillRequirements) {
        this.skillRequirements = skillRequirements;
    }

    public String getOtherRequirements() {
        return otherRequirements;
    }

    public void setOtherRequirements(String otherRequirements) {
        this.otherRequirements = otherRequirements;
    }

    public String getContactInfo() {
        return contactInfo;
    }

    public void setContactInfo(String contactInfo) {
        this.contactInfo = contactInfo;
    }

    public JobStatus getStatus() {
        return status;
    }

    public void setStatus(JobStatus status) {
        this.status = status;
    }

    public String getAuditRemark() {
        return auditRemark;
    }

    public void setAuditRemark(String auditRemark) {
        this.auditRemark = auditRemark;
    }

    public Long getAuditBy() {
        return auditBy;
    }

    public void setAuditBy(Long auditBy) {
        this.auditBy = auditBy;
    }

    public LocalDateTime getAuditAt() {
        return auditAt;
    }

    public void setAuditAt(LocalDateTime auditAt) {
        this.auditAt = auditAt;
    }

    public LocalDateTime getPublishAt() {
        return publishAt;
    }

    public void setPublishAt(LocalDateTime publishAt) {
        this.publishAt = publishAt;
    }

    public LocalDateTime getExpireAt() {
        return expireAt;
    }

    public void setExpireAt(LocalDateTime expireAt) {
        this.expireAt = expireAt;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }

    public List<JobApplication> getApplications() {
        return applications;
    }

    public void setApplications(List<JobApplication> applications) {
        this.applications = applications;
    }

    public Long getAssignedWorkerId() {
        return assignedWorkerId;
    }

    public void setAssignedWorkerId(Long assignedWorkerId) {
        this.assignedWorkerId = assignedWorkerId;
    }

    public LocalDateTime getAssignedAt() {
        return assignedAt;
    }

    public void setAssignedAt(LocalDateTime assignedAt) {
        this.assignedAt = assignedAt;
    }

    
    /**
     * 岗位类型枚举
     */
    public enum JobType {
        FULL_TIME("全职"),
        PART_TIME("兼职"),
        TEMPORARY("临时工"),
        INTERNSHIP("实习"),
        CONTRACT("合同工");
        
        private final String description;
        
        JobType(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
    
    /**
     * 薪资类型枚举
     */
    public enum SalaryType {
        HOURLY("按小时"),
        DAILY("按日"),
        MONTHLY("按月");
        
        private final String description;
        
        SalaryType(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
    
    /**
     * 岗位状态枚举
     */
    public enum JobStatus {
        DRAFT("草稿"),
        PUBLISHED("已发布"),
        ACTIVE("活跃"),
        WAITING_FOR_WORKER("等待用工中"),
        WORKER_ASSIGNED("已获取用工"),
        PAUSED("暂停"),
        CLOSED("关闭"),
        COMPLETED("已完成"),
        CANCELLED("取消");
        
        private final String description;
        
        JobStatus(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
}
